package com.choosefine.common.servicemonitor;

import com.google.common.collect.Maps;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author hujj
 * @Date 2017/4/6
 */

/**
 * 服务访问监控
 */
public class ServiceVisit {
    /**
     * 获取服务访问常规参数和访问时间
     *
     * @param startTime
     * @param fullMethodName
     * @param args
     * @param request
     * @param bizSys
     * @return
     */
    public Map<String, Object> getServiceVisitInfo(Long startTime, String fullMethodName, Object[] args,
                                                   HttpServletRequest request, String bizSys) {
        Map<String, Object> serviceVisitInfo = Maps.newHashMap();
        Long endTime = System.currentTimeMillis();
        Long spendTime = endTime - startTime;

        String url = request.getRequestURL().toString();

        String remoteIP = request.getRemoteAddr();//访问者的ip
        String referer = request.getHeader("Referer");
        String token = request.getParameter("token");
        String userCode = request.getParameter("userCode");

        serviceVisitInfo.put("url", url);
        serviceVisitInfo.put("remoteIP", remoteIP);
        serviceVisitInfo.put("token", token);
        serviceVisitInfo.put("userCode", userCode);
        serviceVisitInfo.put("referer", referer);
        serviceVisitInfo.put("fullMethodName", fullMethodName);
        serviceVisitInfo.put("args", args.toString());
        serviceVisitInfo.put("startTime", startTime);

        serviceVisitInfo.put("endTime", endTime);
        serviceVisitInfo.put("spendTime", spendTime);
        serviceVisitInfo.put("bizSys", bizSys);
        return serviceVisitInfo;
    }
}
